function verifyLogin() {
    // 获取输入框节点
    const usernameEle = document.querySelector('input[name="username"]')
    const emailEle = document.querySelector('input[name="email"]')
    const passwordEle = document.querySelector('input[name="password"]')

    // 获取提示节点
    const usernamePEle = document.querySelector('.usernamemsg')
    const emailPEle = document.querySelector('.emailmsg')
    const passwordPEle = document.querySelector('.passwordmsg')

    // 获取登录按钮
    const enterBtn = document.querySelector('.enter')
    // 获取取消按钮节点
    const enrollBtn = document.querySelector('.enroll')

    // 用户名非空验证
    const nonNullUserName = () => {
        if (usernamePEle.value == '') {
            usernamePEle.innerHTML = '用户名不能为空'
            return false
        } else {
            usernamePEle.innerHTML = ''
            return true
        }
    }

    // 邮箱非空验证
    const nonNullEmail = () => {
        if (emailEle.value == '') {
            emailPEle.innerHTML = '邮箱不能为空'
            return false
        } else {
            emailPEle.innerHTML = ''
            return true
        }
    }

    // 密码非空验证
    const nonNullPassword = () => {
        if (passwordEle.value == '') {
            passwordPEle.innerHTML = '密码不能为空'
            return false
        } else {
            passwordPEle.innerHTML = ''
            return true
        }
    }

    // 检验邮箱是否符合规则
    const strengthEmail = () => {
        /*
         规则: 有@符
            @左边至有一个字符, 字符是 _、大小写字母、数字
            @右边.com结束,.com前面至少有两个字符,字符是 _、大小写字母、数字
        */
        let emailReg = /[_a-zA-Z0-9]+@[_a-zA-Z0-9]{2,}\.com$/
        if (!emailReg.test(emailEle.value)) {
            emailPEle.innerHTML = '邮箱格式不正确'
            return false
        } else {
            emailPEle.innerHTML = ''
            return true
        }
    }

    // 检验密码是否符合规则
    const strengthPassword = () => {
        // 密码必须是大写字母开头,是字母和数字组合，至少8位
        let passwordReg = /[A-Z][a-zA-Z0-9]{7,}/
        if (!passwordReg.test(passwordEle.value)) {
            passwordPEle.innerHTML = '密码必须是大写字母开头,是字母和数字组合，至少8位'
            return false
        } else {
            passwordPEle.innerHTML = ''
            return true
        }
    }

    // 用户名失去焦点验证
    usernameEle.onblur = function () {
        nonNullUserName()
    }

    // 邮箱失去焦点验证
    emailEle.onblur = function () {
        let isNonNullEmail = nonNullEmail()
        if (!isNonNullEmail) {
            return
        }
        strengthEmail()
    }

    // 密码失去焦点验证
    passwordEle.onblur = function () {
        let isNonNullPassword = nonNullPassword()
        if (!isNonNullPassword) {
            return
        }
        strengthPassword()
    }

    // 实现登录功能
    enterBtn.onclick = function () {

        // 进行非空验证
        let isNonNullUserName = nonNullUserName()
        let isNonNullPassword = nonNullPassword()
        let isNonNullEmail = nonNullEmail()
        if (!isNonNullUserName || !isNonNullPassword || !isNonNullEmail) {
            return
        }

        // 检验密码以及邮箱是否符合规则
        let isStrengthPassword = strengthPassword()
        let isStrengthEmail = strengthEmail()
        if (!isStrengthPassword || !isStrengthEmail) {
            return
        }

        // 登录成功
        // function loadIndex() {
            location.href = './index.html'
        // }
    }
    enrollBtn.onclick = function() {
        usernameEle.value == ''
        emailEle.value == ''
        passwordEle.value == ''
        usernamePEle.value == ''
        emailPEle.value == ''
        passwordPEle.value == ''
    }
}

// function homePages() {
//     location.href="./login.html"
// }

// homePages()
verifyLogin()